package com.lemner.ke.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.lemner.ke.R;
import com.lemner.ke.base.BaseActivity;
import com.lemner.ke.base.BaseListener;
import com.lemner.ke.bean.SuccessBean;
import com.lemner.ke.model.persional.ResetNameModel;
import com.lemner.ke.util.SpUtils;

/**

* 作者：张恺

* 时间：2018/9/25

* 类描述：修改昵称页面

*/

public class NameActivity extends BaseActivity {
    private EditText et_name;
    private ImageView iv_back;
    private Button btn_save;

    @Override
    public int getLayoutFile() {
        return R.layout.activity_name;
    }

    @Override
    public void initView() {
    et_name=findViewById(R.id.et_name_name);
    iv_back=findViewById(R.id.iv_name_back);
    btn_save=findViewById(R.id.btn_name_save);
    }

    @Override
    public void initEvent() {
        iv_back.setOnClickListener(this);
        btn_save.setOnClickListener(this);
    }

    @Override
    public void initData() {
        Bundle bundle = getIntent().getExtras();
        String name = bundle.getString("name");
        et_name.setText(name);
    }



    @Override
    protected void initSetting() {
        topBarEnable=false;
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.iv_name_back:
                finish();
                hideSoftKeyBoard(NameActivity.this);
                break;
            case R.id.btn_name_save:
                if (et_name.getText().toString().isEmpty()) {
                    showToast("请输入昵称！");
                } else {
                    new ResetNameModel().resetName(SpUtils.getString(NameActivity.this, SpUtils.USERIDS), SpUtils.getString(NameActivity.this, SpUtils.MOBILE_PHOE), et_name.getText().toString(),
                            new BaseListener<SuccessBean>() {
                                @Override
                                public void onResponse(SuccessBean successBean) {
                                    showToast("修改昵称成功！");
                                    finish();
                                }

                                @Override
                                public void onFail(String msg) {

                                }
                            });
                    break;
                }
        }

    }

}
